package logic

import (
	"context"
	"database/sql"
	"t-go-zero/service/user/model"
	"time"

	"t-go-zero/service/user/rpc/internal/svc"
	"t-go-zero/service/user/rpc/userclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type ARoleAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewARoleAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ARoleAddLogic {
	return &ARoleAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ARoleAddLogic) ARoleAdd(in *userclient.ARoleAddReq) (*userclient.CommonResp, error) {
	// 我们去调用 model 里的 添加方法
	_, err := l.svcCtx.ARoleModel.Insert(l.ctx, &model.ARole{
		CreatedAt:   time.Now(),                                                // 创建时间
		Name:        in.Name,                                                   // 角色名称
		Remark:      sql.NullString{String: in.Remark, Valid: in.Remark != ""}, // 备注
		CreatedName: in.CreatedName,                                            // 创建人
	})
	if err != nil {
		return nil, err
	}

	return &userclient.CommonResp{}, nil
}
